package cn.lili.controller.common;

import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.OperationalJudgment;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.security.enums.UserEnums;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.common.vo.SearchVO;
import cn.lili.modules.file.entity.File;
import cn.lili.modules.file.entity.dto.FileOwnerDTO;
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.store.entity.dos.Market;
import cn.lili.modules.store.entity.dto.BillSearchParams;
import cn.lili.modules.store.entity.vos.BillListVO;
import cn.lili.modules.store.entity.vos.MarketSearchParams;
import cn.lili.modules.store.entity.vos.StoreSearchParams;
import cn.lili.modules.store.entity.vos.StoreVO;
import cn.lili.modules.store.service.MarketService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * 市场信息信息接口
 *
 * @author lxc
 */
@RestController
@Api(tags = "市场信息接口")
@RequestMapping("/common/market")
public class MarketController {

    @Autowired
    private MarketService marketService;

    @ApiOperation(value = "获取全部市场列表")
    @GetMapping(value = "/list")
    public ResultMessage<List<Market>> list() {
        return ResultUtil.data(marketService.list());
    }

    @ApiOperation(value = "获取市场分页列表")
    @GetMapping
    public ResultMessage<IPage<Market>> getByPage(MarketSearchParams entity, PageVO page) {
        return ResultUtil.data(marketService.findByConditionPage(entity, page));
    }


    @ApiOperation(value = "新增市场")
    @PostMapping(value = "/create", consumes = "application/json", produces = "application/json")
    public ResultMessage<Market> save(@Valid @RequestBody Market market) {
        marketService.save(market);
        return ResultUtil.success();
    }


    @ApiOperation(value = "修改市场")
    @PutMapping(value = "/update/{marketId}", consumes = "application/json", produces = "application/json")
    public ResultMessage<Market> update(@RequestBody Market market, @PathVariable String marketId) {
        market.setId(marketId);
        marketService.updateById(market);
        return ResultUtil.success();
    }

    @ApiOperation(value = "通过id获取")
    @GetMapping(value = "/get/{id}")
    public ResultMessage<Market> get(@PathVariable String id) {
        Market market = marketService.getById(id);
        return ResultUtil.data(market);
    }

}
